/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import Definitions.Globals;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Jirka
 */
@Entity
@Table(name = "club")
@NamedQueries({@NamedQuery(name = "Club.findAll", query = "SELECT c FROM Club c"), @NamedQuery(name = "Club.findByClubId", query = "SELECT c FROM Club c WHERE c.clubId = :clubId"), @NamedQuery(name = "Club.findByName", query = "SELECT c FROM Club c WHERE c.name = :name"), @NamedQuery(name = "Club.findByAccount", query = "SELECT c FROM Club c WHERE c.account = :account")})
public class Club implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    @Column(name = "club_id", nullable = false)
    private Integer clubId;
    @Column(name = "name")
    private String name;
    @Column(name = "account")
    private Integer account;
    @JoinTable(name = "participation", joinColumns = {@JoinColumn(name = "club_id", referencedColumnName = "club_id")}, inverseJoinColumns = {@JoinColumn(name = "league_id", referencedColumnName = "league_id")})
    @ManyToMany
    private Collection<League> leagueCollection;
    @OneToMany(mappedBy = "club")
    private Collection<Player> playersCollection;
    @OneToMany(mappedBy = "awayClub")
    private Collection<Game> awayMatchesCollection;
    @OneToMany(mappedBy = "homeClub")
    private Collection<Game> homeMatchesCollection;
    @OneToMany(mappedBy = "club")
    private Collection<Offer> offersCollection;
    @JoinColumn(name = "manager_login", referencedColumnName = "login")
    @ManyToOne(optional = false)
    private Manager manager;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "club")
    private Stadium stadium;

    public Club() {
        this.account = Globals.INIT_CLUB_MONEY;
        this.leagueCollection = new ArrayList<League>();
        this.playersCollection = new ArrayList<Player>();
        this.awayMatchesCollection = new ArrayList<Game>();
        this.homeMatchesCollection = new ArrayList<Game>();
        this.offersCollection = new ArrayList<Offer>();
    }

    public Club(Integer clubId) {
        this.clubId = clubId;
        this.account = Globals.INIT_CLUB_MONEY;
        this.leagueCollection = new ArrayList<League>();
        this.playersCollection = new ArrayList<Player>();
        this.awayMatchesCollection = new ArrayList<Game>();
        this.homeMatchesCollection = new ArrayList<Game>();
        this.offersCollection = new ArrayList<Offer>();
    }

    void rename(String newName) {
        this.name = newName;
    }

    public Integer getClubId() {
        return clubId;
    }

    public void setClubId(Integer clubId) {
        this.clubId = clubId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAccount() {
        return account;
    }

    public void setAccount(Integer account) {
        this.account = account;
    }

    public Collection<League> getLeagueCollection() {
        return leagueCollection;
    }

    public void setLeagueCollection(Collection<League> leagueCollection) {
        this.leagueCollection = leagueCollection;
    }

    public Collection<Player> getPlayersCollection() {
        return playersCollection;
    }

    public void setPlayersCollection(Collection<Player> playersCollection) {
        this.playersCollection = playersCollection;
    }

    public Collection<Game> getAwayMatchesCollection() {
        return awayMatchesCollection;
    }

    public void setAwayMatchesCollection(Collection<Game> gamesCollection) {
        this.awayMatchesCollection = gamesCollection;
    }

    public Collection<Game> getHomeMatchesCollection() {
        return homeMatchesCollection;
    }

    public void setHomeMatchesCollection(Collection<Game> gamesCollection) {
        this.homeMatchesCollection = gamesCollection;
    }

    public Collection<Offer> getOffersCollection() {
        return offersCollection;
    }

    public void setOffersCollection(Collection<Offer> offersCollection) {
        this.offersCollection = offersCollection;
    }

    public Manager getManager() {
        return manager;
    }

    public void setManager(Manager manager) {
        this.manager = manager;
    }

    public Stadium getStadium() {
        return stadium;
    }

    public void setStadium(Stadium stadium) {
        this.stadium = stadium;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (clubId != null ? clubId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Club)) {
            return false;
        }
        Club other = (Club) object;
        if ((this.clubId == null && other.clubId != null) || (this.clubId != null && !this.clubId.equals(other.clubId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Club[clubId=" + clubId + "]";
    }

}
